FROM alpine:3.7

ENV NGINX_VERSION 1.15.3
ENV NGINX_RTMP_VERSION 1.2.1
ARG ALPINE_URL=mirrors.aliyun.com

RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_URL}/g" /etc/apk/repositories

# Build dependencies.
RUN	apk update && apk add	\
  binutils \
  binutils-libs \
  build-base \
  ca-certificates \
  gcc \
  libc-dev \
  libgcc \
  make \
  musl-dev \
  openssl \
  openssl-dev \
  pcre \
  pcre-dev \
  pkgconf \
  pkgconfig \
  zlib-dev \
  tzdata \
  aria2

# nginx
WORKDIR /usr/local/nginx

RUN mkdir -p /var/data && mkdir -p /www/static && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ADD ./nginx/nginx-${NGINX_VERSION}.tar.gz .

ADD ./nginx/v1.2.1.tar.gz .

# Compile nginx with nginx-rtmp module.
RUN cd nginx-${NGINX_VERSION} && \
  ./configure \
  --prefix=/usr/local/nginx \
  --with-select_module \
  --with-poll_module \
#  --with-file-aio \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_gzip_static_module \
  --with-http_secure_link_module \
  --with-http_sub_module \
  --with-http_stub_status_module \
  --with-http_mp4_module \
  --with-http_flv_module \
  --add-module=/usr/local/nginx/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
  --conf-path=/usr/local/nginx/nginx.conf \
  --error-log-path=/usr/local/nginx/logs/error.log \
  --http-log-path=/usr/local/nginx/logs/access.log \
  --with-debug && \
  make && make install

# Cleanup.
RUN rm -rf /var/cache/* /usr/local/nginx/nginx-${NGINX_VERSION}

EXPOSE 80 
EXPOSE 6800 

WORKDIR /data/down

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]
